/*
 * Copyright (C) 2011 The Binary Clock Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.geo.android.bclock;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.os.Bundle;
//import android.view.KeyEvent;
//import android.view.Menu;
//import android.view.MenuItem;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.EditText;


public class BinaryClockActivity extends Activity {

	/*
	 * This is the GL Surface View.
	 * Keep it private and if need to publish this member
	 * just create the necessary methods.
	*/
	private BClockGLSurfaceView mBClockView;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (detectOpenGLES20()) {
            // Tell the surface view we want to create an OpenGL ES 2.0-compatible
        	// context, and set an OpenGL ES 2.0-compatible renderer.
        	mBClockView = new BClockGLSurfaceView(this);
        	setContentView(mBClockView);
        } else {
        	setContentView(R.layout.main);
        }
    }

    /*
     * It will only support the OGLES 2.0 or higher
     * Check the version of GL.
     * Be aware the Android Emulator may not support OGLES 2.0
     */
    private boolean detectOpenGLES20() {
        ActivityManager am =
            (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        return (info.reqGlEsVersion >= 0x20000);
    }

    /*
     * (non-Javadoc)
     * @see android.app.Activity#onPause()
     */
    @Override
    protected void onPause() {
        super.onPause();
        if (mBClockView != null) {
        	mBClockView.onPause();
        }
    }
    
    /*
     * (non-Javadoc)
     * @see android.app.Activity#onResume()
     */
    @Override
    protected void onResume() {
        super.onResume();
        if (mBClockView != null) {
        	mBClockView.onResume();
        }
    }    
}